#ifndef BITMAP_H
#define BITMAP_H

#include <string.h>
#include <assert.h>

class Bitmap
{
public:
	Bitmap(size_t size)
	{
		bm_size = size;
		bm_array = new char [size>>shift_num];
		memset(bm_array, 0, size>>shift_num);
	}
	~Bitmap()
	{
		delete [] bm_array;
	}

	void set(size_t pos)
	{
		assert(pos>=0 && pos <bm_size);
		bm_array[pos>>shift_num] |= 0x80>>(pos & 0x7);
	}

	void reset(size_t pos)
	{
		assert(pos>=0 && pos <bm_size);
		bm_array[pos>>shift_num] &= ~(0x80>>(pos & 0x7));
	}

	bool isSet(size_t pos)
	{
		assert(pos>=0 && pos <bm_size);
		return (bm_array[pos>>shift_num] & (0x80>>(pos & 0x7))) != 0;
	}
	void clear()
	{
		memset(bm_array, 0, bm_size>>shift_num);
	}

private:
	size_t bm_size;
	char*  bm_array;

static const int shift_num = 3;
};

#endif